//
//  AllCategroyPartTableViewCell.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/8/10.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "AllCategroyPartTableViewCell.h"

#define labelWidth (SCREEN_WIDTH - 50 - 32) / 3

@implementation AllCategroyPartTableViewCell
{
    NSMutableArray *_buttonArray;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
//        self.backgroundColor = [UIColor colorWithRed:VALUE green:VALUE blue:VALUE alpha:1];
    }
    return self;
}

- (void)setCell{
    
    _buttonArray = [NSMutableArray array];
    
    int temp = 0;
    CGFloat height = 5;
    
    int flag = [_selectNum intValue];
    
    for (int i = 0; i < _array.count; i++) {
        
        UIButton *bgView = [UIButton buttonWithType:UIButtonTypeCustom];
        bgView.frame = CGRectMake(8 + temp * (labelWidth + 8), height, labelWidth, 40);
        bgView.backgroundColor = [UIColor colorWithRed:240/255.0 green:242/255.0 blue:245/255.0 alpha:1];
        bgView.layer.cornerRadius = 5;
        bgView.layer.masksToBounds = YES;
        
        [bgView addTarget:self action:@selector(selectCategroy:) forControlEvents:UIControlEventTouchUpInside];
        
        [bgView setTitle:_array[i] forState:UIControlStateNormal];
        [bgView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        bgView.titleLabel.font = [UIFont systemFontOfSize:13];
        bgView.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        if (i == flag) {
            bgView.backgroundColor = APPCOLOR;
            [bgView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        
        [self.contentView addSubview:bgView];
        
        [_buttonArray addObject:bgView];
        
        temp ++;
    }
}


- (void)selectCategroy:(UIButton *)sender{
    int temp = -1;
    
    for (int i = 0; i < _buttonArray.count; i++) {
        UIButton *button = _buttonArray[i];
        button.backgroundColor = [UIColor colorWithRed:240/255.0 green:242/255.0 blue:245/255.0 alpha:1];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        if (button == sender) {
            button.backgroundColor = APPCOLOR;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            temp = i;
        }
        
    }
    
    _select(sender.titleLabel.text, [NSString stringWithFormat:@"%d", temp]);
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
